
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:pplive/pages/home/home_page.dart';
import 'package:pplive/pages/main/main_page.dart';
import 'package:pplive/pages/message/message_page.dart';
import 'package:pplive/pages/mine/mine_sub_page.dart';
import 'package:pplive/pages/mine/mine_page.dart';
import 'package:pplive/pages/square/photo_page.dart';
import 'package:pplive/pages/square/squareSubPage.dart';
import 'package:pplive/pages/square/square_page.dart';


enum AppPage { main, home, square, mine, message, squareSub, photo, mineSub }

extension AppPageExtension on AppPage {
  static const Map<AppPage, String> _pageRawValue= {
    AppPage.main: '/main',
    AppPage.home: '/home',
    AppPage.square: '/square',
    AppPage.mine: '/mine',
    AppPage.message: '/message',
    AppPage.squareSub: '/square/sub',
    AppPage.photo: '/photo',
    AppPage.mineSub: '/mine/sub',
  };

  String get rawValue => _pageRawValue[this]!;

  Widget getPage() {
    switch (this) {
      case AppPage.main:
        return MainPage();
      case AppPage.home:
        return HomePage();
      case AppPage.square:
        return SquarePage();
      case AppPage.mine:
        return MinePage();
      case AppPage.message:
        return MessagePage();
      case AppPage.squareSub:
        return SquareSubPage();
      case AppPage.photo:
        return PhotoPage();
      case AppPage.mineSub:
        return MineSubPage();
    }
  }

  GetPage<dynamic> createPage() => GetPage(name: this.rawValue, page: () => this.getPage());

  void go([dynamic arguments, Map<String, String>? parameters]) => AppRoute.goto(this, arguments, parameters);
}

class AppRoute {

  static final pages = [
    AppPage.main.createPage(),
    AppPage.home.createPage(),
    AppPage.square.createPage(),
    AppPage.mine.createPage(),
    AppPage.message.createPage(),
    AppPage.squareSub.createPage(),
    AppPage.photo.createPage(),
    AppPage.mineSub.createPage(),
  ];

  static goto(AppPage page, [dynamic arguments, Map<String, String>? parameters = null]) {
    debugPrint("[route] ${page.rawValue} $arguments $parameters");
    Get.toNamed(page.rawValue, parameters: parameters, arguments: arguments);
  }
}